﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>批次工艺变更冻结释放</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
</head>
<body>
    <div class="panelSection">
        <div class="easyui-panel " title="查询区域" style="width: 100%;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <form id="queryForm" action="">
            <div style="margin: 3px 0px 0px 3px">
                <div style="float: left;">
                    <div class="divLabel" style="margin-bottom: 5px">
                        订单号：</div>
                    <input id="txtMfgOrderName" name="MfgOrderName" class="easyui-textbox" style="width: 150px;
                        height: 20px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px">
                        零件号：</div>
                    <input id="txtProductName" name="ProductName" class="easyui-textbox" style="width: 150px;
                        height: 20px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px">
                        批次号：</div>
                    <input id="txtContainerName" name="ContainerName" class="easyui-textbox" style="width: 180px;
                        height: 20px" />
                </div>
                <div style="float: left; margin-left: 10px;">
                    <div class="divLabel" style="margin-bottom: 5px">
                        状态：</div>
                    <select style='width: 100px; height: 20px' id='selStatus' name="Status" data-options="editable:false,panelHeight:'auto'"
                        class='easyui-combobox'>
                    </select>
                </div>
                <div style="float: left; margin-left: 20px">
                    <button id="btnSearch" class="easyui-linkbutton" type="button" data-options="" style="margin-top: 16px;
                        width: 120px">
                        查询</button>
                    <button id="btnReset" class="easyui-linkbutton" type="button" data-options="" style="margin-top: 16px;
                        margin-left: 5px; width: 80px">
                        重置</button>
                </div>
                <div style="clear: both">
                </div>
            </div>
            </form>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="结果区域" style="width: 100%;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px">
                <table id="gdContainerInfo" class="easyui-datagrid" style="width: 100%; height: 350px"
                    data-options="fitColumns:true,rownumbers:true">
                </table>
                <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                    buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]  
                ">
                </div>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="按钮区域" style="width: 100%;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px">
                <button id="btnContainerWfMove" class="easyui-linkbutton" type="button" style="width: 80px;
                    height: 26px; display: none">
                    批次调度</button>
                <button id="btnReleaseApply" class="easyui-linkbutton" type="button" style="width: 80px;
                    height: 26px; display: none">
                    解冻申请</button>
                <button id="btnReleaseAudit" class="easyui-linkbutton" type="button" style="width: 80px;
                    height: 26px; display: none">
                    审核同意</button>
                <button id="btnReleaseBack" class="easyui-linkbutton" type="button" style="width: 80px;
                    height: 26px; display: none">
                    退回申请</button>
            </div>
        </div>
    </div>
    <div id="dgBack" style="display: none;">
        <div style="padding: 3px 0px 0px 3px">
            <div style="float: left;">
                <div class="divLabel" style="margin-bottom: 5px">
                    退回原因：</div>
                <input id="txtBackReason" class="easyui-textbox" style="width: 150px; height: 100px"
                    data-options="multiline:true" />
            </div>
            <div style="float: left;">
                <button id="btnSureBack" class="easyui-linkbutton" type="button" style="width: 80px;
                    height: 26px;">
                    退回</button>
                <button id="btnClose" class="easyui-linkbutton" type="button" style="width: 80px;
                    height: 26px;">
                    关闭</button>
            </div>
        </div>
    </div>
    <div id="dgMove">
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：zhangrj
    日期：2025-08-21
    描述：批次工艺变更冻结释放js
    */
    var page = {
        roleType: "申请人", //默认角色为申请人
        pageTotal: 0,
        pageSize: 20,
        pageNumber: 1,
        statusDefault: 0, //状态下拉默认值
        rootPath: getRootPath(), //网站根路径
        url: getRootPath() + "/Ashx/ContainerWFChangeHoldReleaseHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            page.initPageData();
            customizedEasyuiPagination('pp'); //定制化分页
        },
        //页面事件绑定
        bind: function () {
            //列表加载
            $("#gdContainerInfo").datagrid({
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pageTotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'MFGORDERNAME', title: '订单号', width: 120 },
                 { field: 'PRODUCTNAME', title: '零件号', width: 150 },
                 { field: 'CONTAINERNAME', title: '批次号', width: 180 },
                 { field: 'CONTAINERTYPENAME', title: '批次类型', width: 100 },
                 { field: 'WORKFLOWINFO', title: '在制工艺', width: 180 },
                 { field: 'WORKFLOWSTEPNAME', title: '在制工序', width: 150 },
                 { field: 'LASTNEWWORKFLOWINFO', title: '最新工艺', width: 150 },
                 { field: 'HOLDTIME', title: '冻结时间', width: 130, formatter: function (value, row, index) {
                     if (!isNullOrWhiteSpaceStr(value)) {
                         return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                     }
                 }
                 },
                 { field: 'APPLICANT', title: '申请人', width: 180, hidden: true },
                 { field: 'APPLICATIONTIME', title: '申请时间', width: 150, hidden: true, formatter: function (value, row, index) {
                     if (!isNullOrWhiteSpaceStr(value)) {
                         return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                     }
                 }
                 },
                 { field: 'AUDITOR', title: '审核人', width: 180, hidden: true },
                 { field: 'AUDITTIME', title: '审核时间', width: 150, hidden: true, formatter: function (value, row, index) {
                     if (!isNullOrWhiteSpaceStr(value)) {
                         return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                     }
                 }
                 },
                 { field: 'BACKAUDITOR', title: '退回人', width: 180, hidden: true },
                 { field: 'BACKTIME', title: '退回时间', width: 150, hidden: true, formatter: function (value, row, index) {
                     if (!isNullOrWhiteSpaceStr(value)) {
                         return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                     }
                 }
                 },
                 { field: 'BACKREASON', title: '退回原因', width: 180, hidden: true }
                ]]
            });
            //查询按钮
            $('#btnSearch').on("click", function () {
                page.pageNumber = 1;
                page.searchData();
            });
            //批次调度按钮
            $('#btnContainerWfMove').on("click", function () {
                page.openChangeWFPage();
            });
            //解冻申请按钮
            $('#btnReleaseApply').on("click", function () {
                page.release(1);
            });
            //审核通过按钮
            $('#btnReleaseAudit').on("click", function () {
                page.release(3);
            });
            //解冻退回按钮
            $('#btnReleaseBack').on("click", function () {
                $('#dgBack').dialog({
                    title: "退回弹窗",
                    width: 300,
                    height: 300,
                    modal: true
                });
            });
            //确认退回（弹窗）
            $('#btnSureBack').on("click", function () {
                page.release(2);
            });
            //关闭（弹窗）
            $('#btnClose').on("click", function () {
                $('#dgBack').dialog("close");
            });
            //状态下拉事件
            $("#selStatus").combobox({
                onSelect: function (record) {
                    switch (record.value) {
                        case "0":
                            $("#gdContainerInfo").datagrid("showColumn", "HOLDTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "APPLICANT");
                            $("#gdContainerInfo").datagrid("hideColumn", "APPLICATIONTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "AUDITOR");
                            $("#gdContainerInfo").datagrid("hideColumn", "AUDITTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "BACKAUDITOR");
                            $("#gdContainerInfo").datagrid("hideColumn", "BACKTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "BACKREASON");
                            break;
                        case "1":
                            $("#gdContainerInfo").datagrid("hideColumn", "HOLDTIME");
                            $("#gdContainerInfo").datagrid("showColumn", "APPLICANT");
                            $("#gdContainerInfo").datagrid("showColumn", "APPLICATIONTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "AUDITOR");
                            $("#gdContainerInfo").datagrid("hideColumn", "AUDITTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "BACKAUDITOR");
                            $("#gdContainerInfo").datagrid("hideColumn", "BACKTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "BACKREASON");
                            break;
                        case "2":
                            $("#gdContainerInfo").datagrid("hideColumn", "HOLDTIME");
                            $("#gdContainerInfo").datagrid("showColumn", "APPLICANT");
                            $("#gdContainerInfo").datagrid("showColumn", "APPLICATIONTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "AUDITOR");
                            $("#gdContainerInfo").datagrid("hideColumn", "AUDITTIME");
                            $("#gdContainerInfo").datagrid("showColumn", "BACKAUDITOR");
                            $("#gdContainerInfo").datagrid("showColumn", "BACKTIME");
                            $("#gdContainerInfo").datagrid("showColumn", "BACKREASON");
                            break;
                        case "3":
                            $("#gdContainerInfo").datagrid("hideColumn", "HOLDTIME");
                            $("#gdContainerInfo").datagrid("showColumn", "APPLICANT");
                            $("#gdContainerInfo").datagrid("showColumn", "APPLICATIONTIME");
                            $("#gdContainerInfo").datagrid("showColumn", "AUDITOR");
                            $("#gdContainerInfo").datagrid("showColumn", "AUDITTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "BACKAUDITOR");
                            $("#gdContainerInfo").datagrid("hideColumn", "BACKTIME");
                            $("#gdContainerInfo").datagrid("hideColumn", "BACKREASON");
                            break;
                        default:

                    }
                }
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.searchData();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.searchData();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.clearPage(true, true);
                page.pageNumber = 1; page.pageTotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pageTotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            });
        },
        //初始化页面数据
        initPageData: function () {
            page.post(page.url, { action: "GetWfChangeReleasePageInitData" }, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                var resData = res.ReturnData; //返回的数据
                //绑定状态数据
                $('#selStatus').combobox({
                    valueField: 'value',
                    textField: 'key',
                    data: resData.dtStatus,
                    value: resData.StatusDefault
                });
                page.statusDefault = resData.StatusDefault; //状态下拉默认值
                page.roleType = resData.RoleTypeName; //角色类型
                if (page.roleType === "审核人") {
                    $("#btnContainerWfMove").hide();
                    $("#btnReleaseApply").hide();
                    $("#btnReleaseAudit").show();
                    $("#btnReleaseBack").show();
                }
                else {
                    $("#btnContainerWfMove").show();
                    $("#btnReleaseApply").show();
                    $("#btnReleaseAudit").hide();
                    $("#btnReleaseBack").hide();
                }
                page.clearPage(true, true); //清空页面
            });
        },
        //查询
        searchData: function () {
            var params = {
                pageIndex: page.pageNumber,
                pageSize: page.pageSize
            };
            var queryFormData = $("#queryForm").serializeArray();
            $.each(queryFormData, function () {
                params[this.name] = this.value;
            });
            page.post(page.url, { action: "GetContainerWfChangeHoldList", params: JSON.stringify(params) }, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                page.pageTotal = res.RowCount;
                $("#gdContainerInfo").datagrid('loadData', { total: res.RowCount, rows: res.DBTable });
            });
        },
        //释放（1：申请，2：审核退回，3：审核通过）
        release: function (type) {
            var rows = $("#gdContainerInfo").datagrid("getChecked");
            if (rows === null) {
                displayMessage("未选择批次", false);
                return;
            }
            var params = {
                action: "SaveWfChangeReleaseAuditRecord",
                opearType: type
            }
            if (type === 2) {
                params.backReason = $("#txtBackReason").textbox('getValue');
                if (params.backReason === "" || params.backReason === null) {
                    displayMessage("请填写退回原因", false);
                    return;
                }
            }
            var datas = rows.map(function (item) {
                return {
                    containerId: item.CONTAINERID,
                    containerName: item.CONTAINERNAME,
                    qty: item.QTY,
                    productId: item.PRODUCTID,
                    productName: item.PRODUCTNAME,
                    recordid: item.RECORDID
                }
            });
            params.dtPageData = JSON.stringify(datas); //页面最终提交的数据
            page.post(page.url, params, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                if (type === 2) {
                    $('#dgBack').dialog("close");
                }
                page.searchData();
            });
        },
        //批次调度
        openChangeWFPage: function () {
            var rows = $("#gdContainerInfo").datagrid("getChecked");
            if (rows === null) {
                displayMessage("未选择批次", false);
                return;
            }
            if (rows.length > 1) {
                displayMessage("只能选择一个批次进行调度", false);
                return;
            }
            page.post(page.url, { action: "IsExistAuditRecord", containerID: rows[0].CONTAINERID }, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                var param = [{
                    "MfgOrderName": rows[0].MFGORDERNAME,
                    "ProductBatch": rows[0].CONTAINERNAME,
                    "ContainerType": rows[0].CONTAINERTYPE,
                    "ProductName": rows[0].PRODUCTNAME,
                    "TogetherFlag": rows[0].TOGETHERFLAG,
                    "ProductID": rows[0].PRODUCTID,
                    "ProductDesc": rows[0].PRODUCTDESC,
                    "ProductRevision": rows[0].PRODUCTREV,
                    "WorkFlowStepID": rows[0].WORKFLOWSTEPID,
                    "WorkFlowName": rows[0].WORKFLOWINFO,
                    "WorkFlowID": rows[0].WORKFLOWID,
                    "WorkFlowRevision": rows[0].WORKFLOWREV,
                    "ContainerTypeName": rows[0].CONTAINERTYPENAME,
                    "WorkFlowStepName": rows[0].WORKFLOWSTEPNAME,
                    "Qty": rows[0].QTY,
                    "ContainerName": rows[0].CONTAINERNAME,
                    "ContainerID": rows[0].CONTAINERID,
                    "IsDispatch": rows[0].ISDISPATCH,
                    "IsWorkReport": rows[0].ISWORKREPORT,
                    "IsCommissioning": rows[0].ISCOMMISSIONING,
                    "IsShip": rows[0].ISSHIP,
                    "IsSplit": rows[0].ISSPLIT,
                    "IsHaveSurpass": null,
                    "IsHold": rows[0].ISHOLD,
                    "WorkReportNum": rows[0].WORKREPORTNUM,
                    "type": ""
                }];
                var url = page.rootPath + "/forms/Custom/ContainerOperateManage/MoveNonStandPopupPage.html?" + $.param({ v: new Date().getTime(), parentDiv: "dgMove", pausePage: "0" });
                $('#dgMove').dialog({
                    title: '批次调度',
                    fit: false,
                    top: 10,
                    width: 900,
                    height: 480,
                    closed: false,
                    cache: false,
                    modal: true,
                    content: '<iframe src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="auto"></iframe>',
                    returnData: null,
                    popupData: JSON.stringify(param), //弹出页面的传参
                    onClose: function () {
                        var returnData = $("#dgMove").dialog('options').returnData; //返回数据
                        if (returnData == true) {
                            page.searchData();
                        }
                    }
                });
            });

        },
        //清除页面（查询区域，列表区域，填写区域，是否清空消息）
        clearPage: function (query, list) {
            if (query) {
                $("#txtMfgOrderName").textbox("clear"); //订单号
                $("#txtProductName").textbox("clear"); //件号
                $("#txtContainerName").textbox("clear"); //流水卡
                $("#selStatus").combobox("setValue", page.statusDefault); //状态 
            }
            if (list) {
                clearEasyuiDataGrid("gdContainerInfo"); //清空列表
            }
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    $("body").find(".easyui-linkbutton").each(function () {
                        $(this).linkbutton('enable');
                    });
                }
            });
        }
    }
    $(function () {
        page.init();
    });
</script>
